cmake_minimum_required(VERSION 3.16)

project(widget-browser VERSION 1.0)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick DBus Widgets LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick DBus Widgets LinguistTools REQUIRED)
find_package(ukui-quick COMPONENTS platform framework core REQUIRED)

add_subdirectory(3rd-parties/qtsingleapplication)
include_directories(3rd-parties/qtsingleapplication/src)

set(APP_SOURCES
        main.cpp
        widget-browser-window.cpp
        widget-browser-window.h
        widgets-browser-model.cpp
        widgets-browser-model.h
        widgets-browser-filter-model.cpp
        widgets-browser-filter-model.h
)

file(GLOB TS_FILES i18n/*.ts)
set(RES res.qrc)
qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} ${TS_FILES} OPTIONS -no-obsolete -no-ui-lines)

add_executable(widget-browser ${APP_SOURCES} ${RES} ${QM_FILES})

target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:QT_QML_DEBUG>)
set(TRANSLATION_DIR "/usr/share/widget-browser/translations/")
add_compile_definitions(TRANSLATION_DIR="${TRANSLATION_DIR}")

target_link_libraries(widget-browser
        PRIVATE
        Qt${QT_VERSION_MAJOR}::Core
        Qt${QT_VERSION_MAJOR}::Quick
        Qt${QT_VERSION_MAJOR}::Widgets
        Qt${QT_VERSION_MAJOR}::DBus
        ukui-quick::platform
        ukui-quick::framework
        ukui-quick::core
        qtsingleapplication
)
install(TARGETS widget-browser RUNTIME DESTINATION /usr/bin)
install(FILES ${QM_FILES} DESTINATION "${TRANSLATION_DIR}")
install(FILES data/widget-browser.desktop DESTINATION /usr/share/applications)
install(FILES data/widget-browser.jpg DESTINATION /usr/share/widget-browser)